#ifndef FOOLISHGO_COMPUTERGO_H
#define FOOLISHGO_COMPUTERGO_H


#include "macro_and_enum.h"
#include "GoBoardWithCommonProcess.h"
#include "BoardStack.h"
#include "TranspositionTable.h"

#include <vector>
#include <stack>

class CTestForCBoardStack;

typedef std::vector<int16_t> TSituationBoard;
class CTestForCIntelligence;
typedef struct {
	int32_t pointValue[361][3];
	int32_t jieValue[361];
	int32_t noJieValue;
	int32_t colorToMoveValue[2];
} SBoardElementValue;

class CIntelligence
{
public:
	CIntelligence(int8_t lineCount);
	void Init(void);
	~CIntelligence(void);

	int GetLineCount(void) {return m_LineCount;}

	//void EvaluateSituation(void);
	void Think(const CGoBoardWithCommonProcess &givenPosition, SLocationOnGoBoard *pFoolishMove);

protected:
	inline int LocationToScript(const SLocationOnGoBoard &location) const;
	inline int8_t ScriptToX(int script) const;
	inline int8_t ScriptToY(int script) const;
	//void EvaluateOnePieceInfluence(int script, TPlayerColor color);
	void GenerateRandomMove(CGoBoardWithCommonProcess *pGoBoardWithCommonProcess) const;
	bool WillFillInTrueEye(const CGoBoardWithCommonProcess &goBoardWithCommonProcess,
		const SLocationOnGoBoard &pointToMove) const;
	void RandomPlay(CGoBoardWithCommonProcess *pGoBoardWithCommonProcess, SGameResult *pResult) const;
	int32_t GetZobristHash(const CGoBoardWithCommonProcess &givenPosition) const;
	void GenerateRandomBoardElementValue(void);
	int32_t GetPositive32BitRandomInteger(void) const;
	void UCTAlgorithm(const CGoBoardWithCommonProcess &rootPosition, SLocationOnGoBoard *pBestMove);
	float GetUCBValue(int32_t key, int n) const;
	bool GetMaxUCBSonNode(const CGoBoardWithCommonProcess &father, CGoBoardWithCommonProcess *pSon) const;
	void UpdateInterest(CBoardStack *pBoardStack, const SGameResult &result);
	void GetMaxInterestMove(const CGoBoardWithCommonProcess &givenBoard, SLocationOnGoBoard *pBestMove) const;
	void FileLog(const CGoBoardWithCommonProcess &goBoard, const CString &info, const CString &name) const;
	void CreatLog(const CString &name) const;
	void Log(const CString &str, const CString &name) const;

private:
	DISALLOW_COPY_AND_ASSIGN(CIntelligence);

	friend class CTestForCIntelligence;
	friend class CTestForCBoardStack;

	//CGoBoardWithCommonProcess m_GoBoardWithCommonProess;
	//TSituationBoard m_SituationBoard;
	const int8_t m_LineCount;
	SBoardElementValue m_boardElementValue;
	int32_t m_MaxPlayCount;
	CTranspositionTable m_TranspositionTable;
};


#endif